package AppleCakeMining;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;


public class Transaction implements Comparable {
	private int id;
	private HashMap<Integer, Item> items;

	public Transaction(int id) {
		this.id = id;
		items = new HashMap<Integer, Item>();
	}
	
	public void addItem(Integer id) {
		Item toAdd = GlobalItemList.getInstance().getItem(id);
		items.put(id, toAdd);		
	}

	public void printAllItems() {
		for(Item i:items.values()) {
			System.out.println("Item" + i.getId());
		}
		
	}

	public boolean containsAll(ArrayList<Item> itemSet) {
		for(Item i:itemSet) {
			if(!items.containsKey(i.getId())) {
				return false;
			}
		}
		return true;
	}

	public Collection<Item> getItems() {
		return items.values();
	}

	@Override
	public int compareTo(Object obj) {
		if (!(obj instanceof Transaction)) return -1;
		Transaction t = (Transaction)obj;
		if(id > t.id) return 1;
		if(id < t.id) return -1;
		return 0;
	}

	public int getId() {
		return id;
	}
	
	
}
